package praktikum_I.blatt_II.aufgabe1.Test;

import java.util.*;


import praktikum_I.blatt_II.aufgabe1.Matrix_impl;
import  junit.framework.Assert;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;

import org.junit.Test;
import praktikum_I.blatt_II.aufgabe1.Point;


public class Test_Matrix_inter {

    private Matrix_impl toTest = new Matrix_impl();

    private void fill() {
    	
        test1 = new double[3][3];
        test1[0][0] = 1.0;
        test1[0][1] = 1.0;
        test1[0][2] = 1.0;
        test1[1][0] = 1.0;
        test1[1][1] = 1.0;
        test1[1][2] = 1.0;
        test1[2][0] = 1.0;
        test1[2][1] = 1.0;
        test1[2][2] = 1.0;

        test2 = new double[3][3];
        test2[0][0] = 2.0;
        test2[0][1] = 2.0;
        test2[0][2] = 2.0;
        test2[1][0] = 2.0;
        test2[1][1] = 2.0;
        test2[1][2] = 2.0;
        test2[2][0] = 2.0;
        test2[2][1] = 2.0;
        test2[2][2] = 2.0;
        
       fillInResult.add(2.0);
       fillInResult.add(2.0);
       fillInResult.add(2.0);

       result1 = new ArrayList[3];
       result1[0] = fillInResult;
       result1[1] = fillInResult;
       result1[2] = fillInResult;

       fillInResult2 =  new ArrayList<Double>();
       fillInResult2.add(2.0);
       fillInResult2.add(2.0);
       fillInResult2.add(2.0);

       result2 = new ArrayList[3];
       result2[0] = fillInResult2;
       result2[1] = fillInResult2;
       result2[2] = fillInResult2;


       List<Double> tmp = new ArrayList<Double>();
                          tmp.add(14.0);
                          tmp.add(20.0);
       mulMatrixLoes[0] = tmp;
        tmp = new ArrayList<Double>();
        tmp.add(32.0);
        tmp.add(46.0);
       mulMatrixLoes[1] = tmp;

        tmp = new ArrayList<Double>();
        tmp.add(432.0);
        tmp.add(432.0);
        tmp.add(432.0);

        powMatrixLoes[0] = tmp;
        powMatrixLoes[1] = tmp;
        powMatrixLoes[2] = tmp;

        tmp = new ArrayList<Double>();
        tmp.add(48.0);
        tmp.add(48.0);
        tmp.add(48.0);

        powMatrixLoes_A[0] = tmp;
        powMatrixLoes_A[1] = tmp;
        powMatrixLoes_A[2] = tmp;

        tmp = new ArrayList<Double>();
        tmp.add(12.0);
        tmp.add(12.0);
        tmp.add(12.0);


        powMatrixLoes_B[0] = tmp;
        powMatrixLoes_B[1] = tmp;
        powMatrixLoes_B[2] = tmp;


        for (int i = 0; i < 3; i++)  result3.add(innerRes3);
    }

    double[][] test1;
    double[][] test2;
    List<Double>[] result1;
    List<Double>[] result2;
    
    List<Double> fillInResult = new ArrayList<Double>();
    List<Double> fillInResult2 = new ArrayList<Double>();

    List<List<Double>> result3 = new LinkedList<List<Double>>();
    LinkedList<Double> innerRes3 = new LinkedList<Double>();

    List<Double>[] mulMatrixLoes = new ArrayList[2];
    List<Double>[] powMatrixLoes = new ArrayList[3];
    List<Double>[] powMatrixLoes_A = new ArrayList[3];
    List<Double>[] powMatrixLoes_B = new ArrayList[3];

    double[][] matrixA = {{1.0,1.0,1.0},
            {1.0,1.0,1.0},
            {1.0,1.0,1.0}
            };
    
    double[][] matrixA1 = {{1.0,0.0,1.0},
            			   {1.0,0.0,1.0},
            			   {1.0,0.0,1.0}
            			  };
    
    double[][] matrixA2 = {{1.0,0.0,1.0},
    						{1.0,0.0,1.0},
    						{1.0,0.0,1.0}
    						};

    double[][] matrixB = {{12.0,12.0,12.0},
            {12.0,12.0,12.0},
            {12.0,12.0,12.0}
    		};

    double[][] matrixS = {{72.0,72.0,72.0},
            {72.0,72.0,72.0},
            {72.0,72.0,72.0}
    };

    double[][] matrixT = {{2592.0,2592.0,2592.0},
            {2592.0,2592.0,2592.0},
            {2592.0,2592.0,2592.0}
    };

    
    double[][] matrixC = {{3.0,2.0,1.0},
            			  {1.0,0.0,2.0},
    					 };

    double[][] matrixD = {{1.0,2.0},
            			  {0.0,1.0},
            			  {4.0,0.0}
    					 };
    
    double[][] matrixE = {{7.0,8.0},
			  			  {9.0,2.0},
				 		 };
    
    double[][] matrixF = {{3.5,4.0},
			  			  {4.5,1.0},
	 		 			 };

    double[][] matrixS1 ={{1.0,2.0},
                            {3.0,4.0}};

    double[][] matrixS2 ={{4.0,6.0},
            {5.0,7.0}};



    double[][] matrix_erg_B = {{8,8},{8,8}};
    double[][] matrix_erg_A = {{128,128},{128,128}};
    double[][] matrix_erg_C = {{32,32},{32,32}};
    double[][] matrix_pow = {{2,2},{2,2}};

    // ######### Array[Array]


    @Test
    public void testSumArray() throws Exception {
        fill();
        
//        assertTrue(toTest.equalsArray(test2, toTest.sumArray(test1, matrixA)));
//
//        assertFalse(toTest.equalsArray(matrixE, toTest.sumArray(test1, matrixA)));
    }

    @Test
    public void testMulArray() throws Exception {
    	//M * M
    //	toTest.toStringArray(toTest.mulArray(matrixC,matrixD));
//    	assertTrue(toTest.equalsArray(matrixE, toTest.mulArray(matrixC, matrixD)));
//
//    	assertFalse(toTest.equalsArray(matrixF, toTest.mulArray(matrixC, matrixD)));
    }
    
    @Test
    public void testMulArray2() throws Exception {
    	fill();
    	// M * skalar
//    	assertTrue(toTest.equalsArray(test2, toTest.mulArray(test1, 2)));
//    	assertTrue(toTest.equalsArray(matrixE, toTest.mulArray(matrixF, 2)));
//
//    	assertFalse(toTest.equalsArray(test2, toTest.mulArray(test1, 3)));
    }

    @Test
    public void testPowArray() throws Exception {
        fill();

        // 3er Matrix
//        assertTrue(toTest.equalsArray(matrixB, toTest.powArray(test2, 2)));
//        assertTrue(toTest.equalsArray(matrixS, toTest.powArray(test2, 3)));
//        assertTrue(toTest.equalsArray(matrixT, toTest.powArray(test2, 5)));

        // 2 Matrix

//        assertTrue(toTest.equalsArray(matrix_erg_A, toTest.powArray(matrix_pow, 4)));
//        assertTrue(toTest.equalsArray(matrix_erg_B, toTest.powArray(matrix_pow, 2)));
//        assertTrue(toTest.equalsArray(matrix_erg_C, toTest.powArray(matrix_pow, 3)));
//        assertTrue(toTest.equalsArray(matrix_pow, toTest.powArray(matrix_pow, 1)));
//
//        assertFalse(toTest.equalsArray(matrix_erg_C, toTest.powArray(matrix_pow, 1)));
//        assertFalse(toTest.equalsArray(matrix_erg_C, toTest.powArray(matrix_pow, 4)));

    }

    // ######### Array[LinkedList]







    // ######### LinkedList[LinkedList]

    @Test
    public void testSumList() throws Exception {

       fill();

        //toTest.toStringList(toTest.sumList(test1,matrixA));

    }

    @Test
    public void testCreateRandomMatrix() throws Exception {
        Set<Point> notNullSet = new HashSet<Point>();
        Point point = new Point(2,5);
        notNullSet.add(point);
        point = new Point(5,2);
        notNullSet.add(point);
        point = new Point(1,1);
        notNullSet.add(point);
        point = new Point(2,3);
        notNullSet.add(point);

        double[][] mnMatrix = toTest.createRandomMatrix(25, notNullSet);

        System.out.println("Die Matrix: " + toTest.toStringArray(mnMatrix));

    }


    @Test
    public void testListPointAdd() throws Exception {
        List<Point> result = new ArrayList<Point>();
        result.add(new Point(1,1,2));
        result.add(new Point(1,2, 6));
        result.add(new Point(2,1, 10));
        result.add(new Point(2,2, 1));


        List<Point> matrix_A = new ArrayList<Point>();
        matrix_A.add(new Point(1,1,1));
        matrix_A.add(new Point(1,2,3));
        matrix_A.add(new Point(2,1,5));
        matrix_A.add(new Point(2,2,-3));


        List<Point> matrix_B = new ArrayList<Point>();
        matrix_B.add(new Point(1,1,1));
        matrix_B.add(new Point(1,2,3));
        matrix_B.add(new Point(2,1,5));
        matrix_B.add(new Point(2,2,4));




        assertEquals("List<Point> Add", new HashSet<Point>(result), new HashSet<Point>(toTest.sumList(matrix_A, matrix_B)));
    }

    @Test
    public void testListPointSkalar(){
        List<Point> result = new ArrayList<Point>();
        result.add(new Point(1,1,-50));
        result.add(new Point(1,2, 25));
        result.add(new Point(2,1, 10));
        result.add(new Point(2,2, 5));


        List<Point> matrix_B = new ArrayList<Point>();
        matrix_B.add(new Point(1,1,10));
        matrix_B.add(new Point(1,2,-5));
        matrix_B.add(new Point(2,1,-2));
        matrix_B.add(new Point(2,2,-1));

        assertEquals("List<Point> Skalar", new HashSet<Point>(result), new HashSet<Point>(toTest.mulList(matrix_B, -5)));

        assertEquals("List<Point> Skalar", new HashSet<Point>(new ArrayList<Point>()), new HashSet<Point>(toTest.mulList(matrix_B, 0)));
    }


    @Test
    public void testListPointMul(){
        List<Point> result = new ArrayList<Point>();
        result.add(new Point(1,1,16));
        result.add(new Point(1,2, 15));
        result.add(new Point(2,1, -10));
        result.add(new Point(2,2, 3));


        List<Point> matrix_A = new ArrayList<Point>();
        matrix_A.add(new Point(1,1,1));
        matrix_A.add(new Point(1,2,3));
        matrix_A.add(new Point(2,1,5));
        matrix_A.add(new Point(2,2,-3));


        List<Point> matrix_B = new ArrayList<Point>();
        matrix_B.add(new Point(1,1,1));
        matrix_B.add(new Point(1,2,3));
        matrix_B.add(new Point(2,1,5));
        matrix_B.add(new Point(2,2,4));

        assertEquals("List<point> Mul", new HashSet<Point>(result), new HashSet<Point>(toTest.mulList(matrix_A,matrix_B)));


    }







}


